package com.zscat.mallplus.center.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zscat.mallplus.center.BaseController;
import com.zscat.mallplus.center.entity.CenterItem;
import com.zscat.mallplus.center.service.ICenterItemService;
import com.zscat.mallplus.utils.CommonResult;

import lombok.extern.slf4j.Slf4j;

/**
 * 金币余额明细Controller
 * 
 * @author Wsen
 * @date 2020-09-20
 */
@Slf4j
@RestController
@RequestMapping("/center/item")
public class CenterItemController extends BaseController
{
    @Resource
    private ICenterItemService centerItemService;

    /**
     * 查询金币余额明细列表
     */
//    @PreAuthorize("@ss.hasPermi('center:item:list')")
    @GetMapping("/list")
    public Object list(CenterItem centerItem,
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
    	
    	System.out.println("jinrufangfa");
		try {
			return new CommonResult().success(centerItemService.page(new Page<CenterItem>(pageNum, pageSize), new QueryWrapper<>(centerItem).orderByDesc("id")));
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		return new CommonResult().failed();
	}

    /**
     * 获取金币余额明细详细信息
     */
//    @PreAuthorize("@ss.hasPermi('center:item:query')")
    @GetMapping(value = "/{id}")
    public Object getInfo(@PathVariable("id") Long id)
    {
        return new CommonResult().success(centerItemService.selectCenterItemById(id));
    }

    /**
     * 新增金币余额明细
     */
//    @PreAuthorize("@ss.hasPermi('center:item:add')")
    @PostMapping
    public Object add(@RequestBody CenterItem centerItem)
    {
        return toAjax(centerItemService.insertCenterItem(centerItem));
    }

    /**
     * 修改金币余额明细
     */
//    @PreAuthorize("@ss.hasPermi('center:item:edit')")
    @PutMapping
    public Object edit(@RequestBody CenterItem centerItem)
    {
        return toAjax(centerItemService.updateCenterItem(centerItem));
    }

    /**
     * 删除金币余额明细
     */
//    @PreAuthorize("@ss.hasPermi('center:item:remove')")
	@DeleteMapping("/{ids}")
    public Object remove(@PathVariable Long[] ids)
    {
        return toAjax(centerItemService.deleteCenterItemByIds(ids));
    }
}
